package com.shop.front.dao.store;

import com.shop.jpa.BaseDao;
import com.shop.domain.store.StoreProductAttrValue;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface StoreProductAttrValueDao extends BaseDao<StoreProductAttrValue, Long> {

    public StoreProductAttrValue findByProductIdAndSuk(Long productId, String suk);

    @Modifying(clearAutomatically = true)
    @Query("update StoreProductAttrValue set stock = stock - ?2 where id = ?1 and stock - ?2 >= 0")
    int subtractStock(Long id, int num);

    @Modifying(clearAutomatically = true)
    @Query("update StoreProductAttrValue set sales = sales + ?2 where id = ?1")
    int addSales(Long id, int num);
}
